// components/order/list.js
import { cancel } from '../../api/order.js';
const util = require('../../utils/util.js')
let app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    orderData: {
      type: Object,
      value: null,
    }
  },
  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
      console.log(this.data.orderData)
      this.data.orderData.subPrice = this.data.orderData.subPrice.toFixed(2)
      this.setData({
        orderData: this.data.orderData
      })
    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  /**
   * 组件的初始数据
   */
  data: {
    img: 'https://icweiliimg1.pstatp.com/weili/l/540018848208912837.webp'
  },
  created() {
    console.log(this.data.orderData)
  },
  /**
   * 组件的方法列表
   */
  methods: {
    refundsclick() {
      wx: wx.navigateTo({
        url: '/pages/member/order/refund?id=' + this.data.orderData.id,
      })
    },
    detailsClick() {
      wx: wx.navigateTo({
        url: '/pages/member/order/refund_details?id=' + this.data.orderData.id,
      })
    },
    cancelOrder(e) { // 取消订单
      console.log(e)
      wx.showModal({
        title: '确认取消订单？',
        content: '取消后可在已关闭订单再次购买',
        success: (res) => {
          if (res.confirm) {
            console.log('用户点击确定')
            this.loadCancel(this.data.orderData.id)
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    },
    loadCancel(data) {
      console.log(data)
      this.triggerEvent('loadCancel')
      // cancel(data).then(
      //   res => {
      //     console.log(res)
      //     if (res.type == 'success') {
      //       wx.showToast({
      //         title: res.content,
      //       })
      //       this.data.findClick(this.data.id)
      //     }
      //   }
      // ).catch(error => {
      //   console.log(error)
      // })
    },
    payment(e) { // 付款
      console.log(e)
    },
    refund(e) { // 退款
      console.log(e)
    },
    remindShipping(e) { // 提醒发货
      console.log(e)
    },
    lookLogistics(e) { // 查看物流
      console.log(e)
    },
    confirmReceipt(e) { // 确认收货
      console.log(e)
    },
    again(e) { // 再次购买
      console.log(e)
    },
    evaluate(e) { // 评价
      console.log(e)
    }
  }
})
